package tournamentmanager;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

public class Preferences implements Serializable {

  private static final long serialVersionUID = 6006192811622280835L;

  private static final int ROBIN = 0;

  private static final int SIMUL = 1;

  public static final String TOURNEYMAN_PREFERENCES = ".tourneymanPreferences";

  private int selectedTournament;

  private RoundRobinTournament roundRobinTournament;

  private SimulTournament simulTournament;

  private List<ChessEngine> preConfEnginesLst;

  public void setPreConfEnginesLst(List<ChessEngine> preConfEnginesLst) {
    this.preConfEnginesLst = preConfEnginesLst;
  }

  public List<ChessEngine> getPreconfEnginesLst() {
    return preConfEnginesLst;
  }

  public void setCurrentTournament(Tournament tournament) {
    if (tournament instanceof RoundRobinTournament) {
      roundRobinTournament = (RoundRobinTournament) tournament;
      selectedTournament = ROBIN;
    }
    if (tournament instanceof SimulTournament) {
      simulTournament = (SimulTournament) tournament;
      selectedTournament = SIMUL;
    }
  }

  public Tournament getCurrentTournament() {
    if (selectedTournament == ROBIN) {
      return roundRobinTournament;
    }
    if (selectedTournament == SIMUL) {
      return simulTournament;
    }
    return roundRobinTournament;
  }


  public RoundRobinTournament getRoundRobinTournament() {
    return roundRobinTournament;
  }

  public SimulTournament getSimulTournament() {
    return simulTournament;
  }


  public void setRoundRobinTournament(RoundRobinTournament roundRobinTournament) {
    this.roundRobinTournament = roundRobinTournament;
  }

  public void setSimulTournament(SimulTournament simulTournament) {
    this.simulTournament = simulTournament;
  }

  public void save() throws IOException {
    Util.saveToFile(this, TOURNEYMAN_PREFERENCES);
  }

}
